package com.pureut.equipment.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.equipment.domain.EquipmentKnowledge;
import com.pureut.equipment.domain.dto.EquipmentKnowledgeDto;
import com.pureut.equipment.domain.vo.EquipmentKnowledgeVo;
import com.pureut.equipment.service.IEquipmentKnowledgeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description 设备知识库
 * @Date 23-04-23
 * @Author hl
 **/
@RestController
@RequestMapping("/knowledge")
public class EquipmentKnowledgeController extends BaseController {

    @Resource
    private IEquipmentKnowledgeService equipmentKnowledgeService;

    /**
     * 查询设备知识库
     */
    @RequiresPermissions("device:knowledge:list")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentKnowledgeVo equipmentKnowledgeVo)
    {
        startPage();
        List<EquipmentKnowledgeDto> list = equipmentKnowledgeService.selectKnowledgeList(equipmentKnowledgeVo);
        return getDataTable(list);
    }

    /**
     * 新增设备知识库
     */
    @RequiresPermissions("device:knowledge:add")
    @Log(title = "设备知识库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addPlan(@RequestBody EquipmentKnowledge equipmentKnowledge){
        return toAjax(equipmentKnowledgeService.insertEquipmentKnowledge(equipmentKnowledge));
    }

    /**
     * 修改设备知识库
     */
    @RequiresPermissions("device:knowledge:edit")
    @Log(title = "设备知识库", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody EquipmentKnowledge equipmentKnowledge){
        return toAjax(equipmentKnowledgeService.updateEquipmentKnowledge(equipmentKnowledge));
    }

    /**
     * 根据编号获取详细信息
     */
    @RequiresPermissions("device:knowledge:query")
    @GetMapping(value = "/{knowledgeId}")
    public AjaxResult getInfo(@PathVariable("knowledgeId") long knowledgeId)
    {
        return AjaxResult.success(equipmentKnowledgeService.selectKnowledgeById(knowledgeId));
    }

    /**
     * 删除设备知识库
     */
    @RequiresPermissions("device:knowledge:remove")
    @Log(title = "设备知识库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{knowledgeId}")
    public AjaxResult remove(@PathVariable("knowledgeId") long knowledgeId) {
        return toAjax(equipmentKnowledgeService.deleteKnowledgeById(knowledgeId));
    }

    @GetMapping("/list1")
    public TableDataInfo list1() {
        List<Map<String, String>> list = equipmentKnowledgeService.selectKnowledgeById1();
        return getDataTable(list);
    }

}
